<?php


namespace app\index\model;
use think\Db;
use think\Model;
//地区
class Region extends Model
{
    protected function  selProvide(){

    }
    public function selAdd(){
        // TODO 请统一使用model类，不使用助手函数
        $data = $this->table('region')->field('cri_name,cri_code')->where('cir_code','=','1')->select();

    }
    public function  selcounty($provide){
        // TODO 请统一使用model类，不使用助手函数
        $data = $this
            ->table('region')
            ->field('cri_short_name')
            ->where('cri_parent_code','=',$provide)
            ->select();
        return$data;
    }

    //通过省份找出code
    public function searchProvide($provide){
        // TODO 请统一使用model类，不使用助手函数
        $data = $this->table('region')->field('cri_code')->where('cri_short_name','=',$provide)->find();
        return $data;
    }
    //通过省份code找出省份里的城市
    public function searchCity($provideCode){
        // TODO 请统一使用model类，不使用助手函数
        $data =$this->table('region')->field('cri_short_name')->where('cri_parent_code','=',$provideCode)->select();
        return $data;
    }

    //找到所有城市
    public function allCity(){
        return $this->field('cri_short_name')->where('cri_level',2)->select();
    }

    //模糊查询到城市
    public function likeAllCity($str){
        return $this->field('cri_short_name')->whereLike('cri_name',"%$str%")->where('cri_level',2)->select();
    }

    //模糊查询到城市及代码
    public function likeCityCode($str){
        return $this->field('cri_short_name,cri_parent_code')->whereLike('cri_name',"%$str%")->where('cri_level',2)->select();
    }
    
    //查询城市及代码(鞍山)
    public function cityCode($str){
        return $this->field('cri_short_name,cri_parent_code')->whereLike('cri_name',"$str%")->where('cri_level',2)->select();
    }

    //通过城市代码找省份
    public function codeFindProvide($str){
        return $this->field('cri_name')->where([
            'cri_code'=>$str,
            'cri_level' => 1
        ])->select();
    }
}
